package com.xyz.graph.common;

/**
 * 公共状态码为1位数：
 *                  0 —> 成功
 *                  -1 —> 失败
 *                  1 —> 参数为空
 *                  2 —> 参数错误
 *                  3 —> 结果为空
 *
 * 不同模块各自的状态码分为3位数：
 *                 第一个标识模块
 *                 第二位标识总体状态
 *                 第三位标识细化状态
 */
public class CommonResult<T> {
    public static final int DEFAULT = -1;

    /**
     * 公共状态码
     * */
    public static final int SUCCESS = 0;     //成功
    public static final int ERROR = -1;     //失败
    public static final int EMPTY_PARAM = 1; //参数为空
    public static final int PARAM_ERROR = 2; //参数错误
    public static final int EMPTY_RESULT = 3;//结果为空

    /**
     * 图管理模块
     * 以1开头
     * 第二位0表示成功，1表示失败
     * */
    public static final int SUCCESS_GREEN_STATE= 100;   //图成功启动，启动量符合用户要求的并发量
    public static final int SUCCESS_YELLOW_STATE = 101; //图已启动，但少于用户要求的并发量
    public static final int FAIL_RED_START = 111;       //图启动失败
    public static final int EMPTY_SERVER = 112;         //无可用服务
    public static final int SEARCH_SERVER_ERROR = 113;  //查询服务错误
    public static final int GRAPH_NOT_EXIST = 114;      //图不存在


    // 图关闭状态码
//    public static final int SUCCESS = 0;
//    public static final int FAILED = 1;

    /**
     * 图查询模块
     * 以2开头
     * 第二位0表示成功，1表示失败
     * */
    public static final int OK_INCOMPLETE = 200;
    public static final int NON_CONNECT = 211;               //无可用连接
    public static final int GRAPH_CONNECT_ERROR = 212;       //获取图连接错误
    public static final int GRAPH_CONNECT_SUCCESS = 201;     //成功获取到可用图连接



    public static final int RETURN_PARTIAL_DATA_ = 201;     //由于数据量限制，仅返回了部分数据
    public static final int MAX_CONCURRENT = 215;     //达到该服务的最大并发数
    public static final int CONNECT_ERROR = 216;     //达到该服务的最大并发数

    // 图查询端的图关闭状态码
    public static final int SUCCESS_BOTH = 202;               // 图关闭启动
    public static final int SUCCESS_ZK_FAILURE_GINS = 213;    // 图在zk端连接已断开，但图实例关闭失败
    public static final int FAILURE_ZK = 214;                 // 图在zk端连接断开失败
    public static final int UNKNOWN_FAILURE = 210;            // 未知错误

    /**
     * 图数据管理状态码
     * 以3开头
     * 第二位0表示成功，1表示失败
     * */
    public static final int VERTEX_NO_EXIST = 311;              //节点不存在
    public static final int EDGE_NO_EXIST = 312;                //边不存在
    public static final int PROP_NO_EXIST = 313;                //属性不存在
    public static final int SUCCESS_OPS_RESULT_ERROR = 303;     //操作执行成功，但结果无效
    public static final int BEYOND_MAX_BATCH_NUM = 314;         //批量操作的点或边数量超过规定的最大数量级



    private int status = DEFAULT;
    private String message;
    private T content;

    public void setStatus(int status) {
        this.status = status;
    }

    public int getStatus() {
        return status;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setContent(T contentValue) {
        this.content = contentValue;
    }

    public T getContent() {
        return content;
    }

    @Override
    public String toString() {
        return "CommonResult{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", content=" + content +
                '}';
    }

    public static CommonResult<Boolean> booleanError(int resultStatus, String resultMsg){
        CommonResult<Boolean> result = new CommonResult<>();
        result.status = resultStatus;
        result.content = false;
        result.message = resultMsg;
        return result;
    }

    public static CommonResult<Boolean> getBooleanResult(int resultStatus, Boolean content, String resultMsg){
        CommonResult<Boolean> result = new CommonResult<>();
        result.status = resultStatus;
        result.content = content;
        result.message = resultMsg;
        return result;
    }
}
